﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataAccessLayer.Models
{
    public interface ICustRepository
    {
        Customer GetCustomer(string name, DateTime dob);
        Customer GetCustomer(int idTypeCode, string idNumber);
        Customer GetCustomer(int customerId);

        IQueryable<Customer> FindAllCustomers();

        void Save();
    }

    public class CustomerRepository : ICustRepository
    {
        private LOSEntities db = new LOSEntities();

        //Query Methods
        public virtual Customer GetCustomer(string name, DateTime dob)
        {
            return db.Customers.SingleOrDefault(d => d.Name == name && d.DOB == dob);
        }

        //Query Methods
        public virtual Customer GetCustomer(int idTypeCode, string idNumber)
        {
            return db.Customers.SingleOrDefault(d => d.IDTypeCode == idTypeCode && d.IDNumber == idNumber);
        }

        public virtual Customer GetCustomer(int customerId)
        {
            return db.Customers.SingleOrDefault(d => d.CustomerId == customerId);
        }

        public IQueryable<Customer> FindAllCustomers()
        {
            return db.Customers;
        }

        //Persistence
        public virtual void Save()
        {
            db.SaveChanges();
        }
    }
}
